﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Medical.Business;
using Medical.Data;
using System.Data;
using System.Data.SqlClient;

public partial class webadmin_DoSeo : AdminPage
{
    /// <summary>
    /// ID
    /// </summary>
    protected int nID;
    protected void Page_Load(object sender, EventArgs e)
    {
        nID = Convert.ToInt32(Common.GetQueryValue("id", 0));
        if (!Page.IsPostBack)
        {
            //页面数据初始化
            InitData();
        }
    }

    /// <summary>
    /// 权限控制
    /// </summary>
    /// <returns></returns>
    public override long GetNeededFeatures()
    {
        return AdminFEATURE.Site;
    }

    protected void InitData()
    {
        DataTable dtSeo = SqlHelper.ExecuteDataset(
            SqlHelper.database, 
            CommandType.Text,
            "select top 1 * from SEO where ID=@ID", 
            new SqlParameter("@ID", nID)).Tables[0];
        if (dtSeo != null && dtSeo.Rows.Count>0)
        {
            ltlName.Text = GetSeoType(Convert.ToInt32(dtSeo.Rows[0]["Type"]));
            txtPageTitle.Text = dtSeo.Rows[0]["PageTitle"].ToString();
            txtPageKeywords.Text = dtSeo.Rows[0]["PageKeywords"].ToString();
            txtPageDescription.Text = dtSeo.Rows[0]["PageDescription"].ToString();
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        bool bResult = SqlHelper.ExecuteNonQuery(
                        SqlHelper.database,
                        CommandType.Text,
                        "update [SEO] set [PageTitle]=@PageTitle,[PageKeywords]=@PageKeywords,[PageDescription]=@PageDescription where [ID]=@ID",
                        new SqlParameter("@PageTitle", txtPageTitle.Text.Trim()),
                        new SqlParameter("@PageKeywords", txtPageKeywords.Text.Trim()),
                        new SqlParameter("@PageDescription", txtPageDescription.Text.Trim()),
                        new SqlParameter("@ID", nID)) > 0;
        if(bResult){
            Until.AlertJS("提交成功！", "top.$('#DialogIframe').dialog('close');");
        }
        else
        {
            Until.Alert("提交失败！");
        }
        Until.SEO = null;

    }

    protected string GetSeoType(int nType)
    {
        switch (nType)
        {
            case 1:
                return "首页";
            case 2:
                return "医院简介";
            case 3:
                return "专家团队";
            case 4:
                return "前沿技术";
            case 5:
                return "高端设备";
            case 6:
                return "热点专题";
            case 7:
                return "专家答疑";
            case 8:
                return "就诊指南";
            case 9:
                return "症状列表";
            case 10:
                return "成功案例";
            default:
                return "";
        }
    }
}